package com.edu.exam.enums.common;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 优先级枚举
 * 用于表示任务或事项的优先级
 *
 * @author System
 * @version 1.0.0
 */
public enum Priority implements BaseEnum {

    /** 低优先级 */
    LOW("LOW", "低"),

    /** 普通优先级 */
    NORMAL("NORMAL", "普通"),

    /** 高优先级 */
    HIGH("HIGH", "高"),

    /** 紧急优先级 */
    URGENT("URGENT", "紧急");

    private final String code;
    private final String description;

    Priority(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    public static Priority fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Priority code cannot be null or empty");
        }
        for (Priority value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        throw new IllegalArgumentException("Unknown Priority code: " + code);
    }

    public static Priority fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            throw new IllegalArgumentException("Priority description cannot be null or empty");
        }
        for (Priority value : values()) {
            if (value.getDescription().equals(description)) {
                return value;
            }
        }
        throw new IllegalArgumentException("Unknown Priority description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}